home *** CD-ROM | disk | FTP | other *** search
- PAGE 60,132
- TITLE CLRKBBUF- Clear Keyboard Buffer
- ; Written by Lew Paper
- ; 11/21/85
-
- PAGE
- ;-----------------------------------------------------------------------------
- ; SWITCH SETTINGS
- ;-----------------------------------------------------------------------------
-
- params EQU 'N' ;'Y' means command line parameters
- dos2dirs EQU 'N' ;'Y' means DOS 2+ directory searches
-
- ;-----------------------------------------------------------------------------
- ; INITIAL DIRECTIVES
- ;-----------------------------------------------------------------------------
-
- ;Standard handles
- StdIn EQU 0 ;Standard input device
- Stdout EQU 1 ;Standard output device
- Stderr EQU 2 ;Standard error device
- Stdaux EQU 3 ;Standard auxiliary device
- Stdprn EQU 4 ;Standard printer device
-
- COMSEG SEGMENT PARA PUBLIC 'CODE'
- ASSUME CS:COMSEG,DS:COMSEG,ES:COMSEG,SS:COMSEG
-
- IF params EQ 'Y'
- ORG 7FH
- cmd_leng DB ? ;Set to 127 and call DOS function
- ;0AH to reenter a command string
- cmdcnt DB ? ;Command line character count
- cmdstr DB 127 DUP (?) ;Command line buffer
- ENDIF ;PARAMS EQ 'Y'
-
- ORG 100H
- start PROC FAR
- JMP ENTRY
-
- ;-----------------------------------------------------------------------------
- ; DATA AREAS
- ;-----------------------------------------------------------------------------
-
- exitval DB 0 ;Exit value
- done_mes DB 'Keyboard buffer cleared',13,10
- done_len EQU $ - done_mes
-
- IF dos2dirs EQ 'Y'
-
- oldDTA: DW ? ;To save old DTA offset
-
- time_rec RECORD hour:5, minute:6, pair_sec:5
- ;pair_sec is two second increments
-
- date_rec RECORD year:7, month:4, day:5
- ;Year 0 is 1980
-
- dos2DTA STRUC ;Structure for dos 2+ DTA
- ;after directory search
- DB 21 DUP (?) ;Reserved for DOS use
- attr DB ? ;Attribute
- time DW ? ;time_rec, but records illegal in STRUC
- date DW ? ;date_rec, but records illegal in STRUC
- lo_size DW ? ;Low word of file's size
- hi_size DW ? ;High word of file's size
- name DB 13 DUP (?) ;ASCIIZ string of NAME.EXT. No
- ;embedded spaces.
- dos2DTA ENDS
-
- dirDTA dos2DTA <> ;DTA for DOS 2+ directory searches
-
- ENDIF ;dos2dirs EQ 'Y'
-
- IF params EQ 'Y'
-
- ; Filename separators: tab, space, +, comma, period, :, ;, =
- fnm_sep DB 9,32,43,44,46,58,59,61
- lfnm_sep EQU THIS BYTE - fnm_sep
-
- ; Filename terminators: ', <, >, |, /, ", [, ]
- fnm_term DB 37, 60, 62, 124, 47, 34, 91, 93
- lfnm_trm EQU THIS BYTE - fnm_term
-
- saved_cx DW ? ;Saved CX
-
- ENDIF ;params EQ 'Y'
-
- ;-----------------------------------------------------------------------------
-
- entry:
-
- IF params EQ 'Y'
-
- MOV CL,cmdcnt ;Count of parameter characters
- CMP CL,0 ;Are there any parameter characters?
- JG someparm ;Yes. Process them
-
- ;No parameters
- ;INSERT DEFAULT CODE HERE
- JMP endparam ;To main program
-
- ;Parameters
- someparm: XOR CH,CH ;Change CX to integer count of chars
- ADD CX,OFFSET cmdcnt ;Offset of last character => CX
- MOV saved_cx,CX ;Save offset of last character
- MOV DI,OFFSET cmdstr ;Offset of first character => DI
-
- ;INSERT PARAMETER HANDLING CODE HERE
-
- ; getpchar does the following things:
- ; If DI indexes a character in the parameter string,
- ; 1. Translates lower case alphabetic characters to upper case.
- ; 2. Sets the translated character into AL.
- ; 3. Sets AH to 0 if the character is not either a filename separator or a
- ; filename terminator, 1 if it is a filename separator or 2 if it is a
- ; filename terminator.
- ; 4. Sets the zero flag on if the character is neither a filename separator
- ; nor a filename terminator, off otherwise.
- ; 5. Increments DI.
- ; If DI indexes a character after the parameter string
- ; 1. Sets AL to 0.
- ; 2. Sets AH to 3.
- ; 3. Sets the zero flag off.
- ;
- endparam:
- ENDIF ;params EQ 'Y'
-
-
- ;INSERT MAIN PROGRAM HERE
- MOV AX,0C06H ;Clear Keyboard, Direct Keyboard I/O
- MOV DL,0FFH ;Accept input if available (throw away)
- INT 21H ;Clear keyboard buffer
- MOV AX,4000H ;Write to file or device
- MOV BX,Stderr ;Standard Error handle
- MOV CX,done_len ;Bytes to write
- MOV DX,OFFSET done_mes ;Pointer to message
- INT 21H ;Write it
- ;-----------------------------------------------------------------------------
- ; RETURN TO DOS
- ;-----------------------------------------------------------------------------
-
- MOV AL,exitval ;Set error level
-
- exit_loc: MOV AH,4CH ;Terminate process function number
- INT 21H ;Return to DOS
- start ENDP
- ;-----------------------------------------------------------------------------
- ; SUBROUTINES
- ;-----------------------------------------------------------------------------
-
- IF params EQ 'Y'
-
- ; getpchar does the following things:
- ; If DI indexes a character in the parameter string,
- ; 1. Translates lower case alphabetic characters to upper case.
- ; 2. Sets the translated character into AL.
- ; 3. Sets AH to 0 if the character is not either a filename separator or a
- ; filename terminator, 1 if it is a filename separator or 2 if it is a
- ; filename terminator.
- ; 4. Sets the zero flag on if the character is neither a filename separator
- ; nor a filename terminator, off otherwise.
- ; 5. Increments DI.
- ; If DI indexes a character after the parameter string
- ; 1. Sets AL to 0.
- ; 2. Sets AH to 3.
- ; 3. Sets the zero flag off.
-
- getpchar PROC
-
- CMP DI,saved_cx ;Is DI out of the string?
- JLE gpcinstr ;No
-
- MOV AX,0300H ;3 => AH, 0 => AL
- AND AH,AH ;Set zero flag off
- JMP gpc_exit ;Done
-
- gpcinstr: MOV AL,[DI] ;Character => AL
- INC DI ;Point DI at next character
-
- MOV CX,OFFSET fnm_sep ;Start check for filename separator
- MOV BX,CX
- MOV CX,lfnm_sep ;Number of characters to compare
- gpc_sep: MOV AH,[BX] ;Separator byte
- INC BX ;Prepare for next separator byte
- CMP AH,AL ;Is it the parameter byte
- LOOPNZ gpc_sep ;No and another separator byte.
- JNE gpcnosep ;Done checking separator bytes.
- MOV AH,1 ;This is a separator byte
- AND AH,AH ;Turn zero flag off
- JMP gpc_exit ;Done
-
-
- gpcnosep: MOV CX,OFFSET fnm_term ;Start check for filename terminator
- MOV BX,CX
- MOV CX,lfnm_sep ;Number of characters to compare
- gpc_term: MOV AH,[BX] ;Terminator byte
- INC BX ;Prepare for next terminator byte
- CMP AH,AL ;Is it the parameter byte
- LOOPNZ gpc_term ;No and another terminator byte.
- JZ gpc_trm1 ;Jump if this is a terminator byte.
- XOR AH,AH ;Convert parameter byte to integer
- CMP AX,32 ;Is it a control character?
- JL gpc_trm1 ;Yes
- CMP AX,127 ;Again, is it a control character?
- JLE gpcnotrm ;No. In legal filename set
- gpc_trm1: MOV AH,2 ;This is a terminator byte
- AND AH,AH ;Turn zero flag off
- JMP gpc_exit ;Done
-
- gpcnotrm: CMP AL,'a' ;Check for lower case letter
- JL gpc_zero
- CMP AL,'z'
- JG gpc_zero
- ADD AX,'A'-'a' ;Convert to upper case
- gpc_zero: XOR AH,AH ;Turn zero flag on
-
- gpc_exit: RET
- getpchar ENDP
-
- ENDIF ;params EQ 'Y'
-
- ;-----------------------------------------------------------------------------
- ; OVERALL END
- ;-----------------------------------------------------------------------------
- COMSEG ENDS
- END start